package com.atguigu;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.srb.base.model.TestModel;
import org.apache.commons.collections4.CollectionUtils;
import org.junit.Test;
import org.springframework.util.StopWatch;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description TODO
 * @Classname test
 * @Date 2022/11/23 17:24
 * @Created by 16342
 * @Author wangchengshan
 */
public class test {

    @Test
    public void testStopWatch() {
        StopWatch sw = new StopWatch("test");
        sw.start("task1");
        // do something
        try {
            Thread.sleep(100);
        } catch (Exception e) {
            System.out.println(e);
        }

        sw.stop();
        sw.start("task2");
        // do something
        try {
            Thread.sleep(200);
        } catch (Exception e) {
            System.out.println(e);
        }

        sw.stop();
        System.out.println("sw.prettyPrint()~~~~~~~~~~~~~~~~~");
        System.out.println(sw.prettyPrint());

    }

    @Test
    public void testString() {
        String name = "慕容张三";
        name = name.substring(0, 2) + "*" + name.substring(name.length() - 1, name.length());
//        System.out.println(name);
//        String idNo = "412823199808011222";
//        idNo = idNo.substring(0,2) + "****" + idNo.substring(6,14) + "****";
//        System.out.println(idNo);
        String memberId = "1234144259872";
        memberId = "****" + memberId.substring(4);
//        System.out.println(memberId);

        String idNo = "3102251996";
        idNo = idNo.substring(0, 3) + "***" + idNo.substring(6, 8) + "**";
        System.out.println(idNo);
    }

    @Test
    public void testDate() {
        Date date = Date.from(Instant.now());
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        String format = ft.format(date);
        System.out.println(format);
        System.out.println(ft);
        System.out.println(date);
    }

    @Test
    public void testcount() {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        long count = list.stream().filter(s -> 2 != s).count();
        System.out.println(count);
    }

    @Test
    public void testEquals() {
        List<Long> l1 = new ArrayList<>();
        List<Long> l2 = new ArrayList<>();

        l1.add(1l);
        l1.add(2l);

        l2.add(2l);
        l2.add(1l);

        System.out.println(CollectionUtils.isEqualCollection(l1, l2));
    }

    @Test
    public void testSame() {
        TestModel t1 = new TestModel();
        t1.setA("a1");
        t1.setB("b1");
        t1.setC("c1");
        t1.setD("d1");
        t1.setE("e1");
        TestModel t2 = new TestModel();
        t2.setA("a1");
        t2.setB("b2");
        t2.setC("c1");
        t2.setD("d1");
        t2.setE("e1");

        List<TestModel> list = new ArrayList<>();
        list.add(t1);
        list.add(t2);

        Map<String, List<TestModel>> collect = list.stream().collect(Collectors.groupingBy(s -> s.getA() + "-" + s.getE() + "-" + s.getC() + "-" + s.getD()));
        for (String s : collect.keySet()) {
            System.out.println(collect.get(s));
        }
//        Map<String, Set<String>> nft1155Map = logs.stream().collect(Collectors.groupingBy(t -> t.getAddress() + "-" + t.getData(), Collectors.mapping(e -> e.getTopics().get(2) + "-" + e.getTopics().get(3), Collectors.toSet())));

    }

    @Test
    public void testSort() {
        List<Long> longList = new ArrayList<>();
        longList.add(1681559661700352l);
        longList.add(1681557995869440l);
        longList.add(1681555552077056l);

        longList.sort(new Comparator<Long>() {
            @Override
            public int compare(Long o1, Long o2) {
                return o1 > o2 ? 1 : -1;
            }
        });
        System.out.println(longList);
    }

    @Test
    public void testRemove() {
        List<Integer> l1 = new ArrayList<>();
        l1.add(1);
        l1.add(2);
        l1.add(3);

        List<Integer> l2 = new ArrayList<>();
        l2.add(1);
//        l2.add(3);
        l2.add(4);
        l1.removeAll(l2);
        System.out.println(l1);
    }

    @Test
    public void testList() {
        List<Integer> l1 = new ArrayList<>();
        l1.add(1);
        l1.add(2);
        l1.add(3);

        List<Integer> l2 = new ArrayList<>();
        l2.add(3);
        l2.add(1);

        Collections.sort(l2, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });
        System.out.println(l2);
    }

    @Test
    public void st() {
        String s = 1 + "/" + 2 + ",";
        String a = s.substring(0, s.length() - 1);
        System.out.println(s);
        System.out.println(a);
    }

    @Test
    public void st1() {
        String a = "1,2";
        String b = "1";
        System.out.println(a.indexOf(b));
    }

    @Test
    public void instant() {
        Instant now = Instant.now();
        Instant plus = now.plus(1, ChronoUnit.DAYS);
        Instant minus = plus.minus(2, ChronoUnit.HOURS);
        System.out.println(now);
        System.out.println(plus);
        System.out.println(minus);
        System.out.println(now.compareTo(plus) + "");

        List<Instant> instantList = new ArrayList<>();
        instantList.add(now);
        instantList.add(plus);
        instantList.add(minus);
        System.out.println(instantList);
        Collections.sort(instantList, new Comparator<Instant>() {
            @Override
            public int compare(Instant o1, Instant o2) {
                return o2.compareTo(o1);
            }
        });
        System.out.println(instantList);
    }

    @Test
    public void testStrinsg() {
        //[["标题","测试马克水印"],["日期","2023\/06\/01 星期四 16:49"],["点位","文一西路1500号"],["接单人",""],["问题描述","测试马克"],["防伪码","V6JGNQF6PX9384"],["上传人","余宣求"]]
        String a = "[[\"标题\",\"测试马克水印\"],[\"日期\",\"2023/06/01 星期四 16:49\"],[\"点位\",\"文一西路1500号\"],[\"接单人\",\"\"],[\"问题描述\",\"测试马克\"],[\"防伪码\",\"V6JGNQF6PX9384\"],[\"上传人\",\"余宣求\"]]";
        String s = "\",\"";

        String b = a.replace("[", "{");
        System.out.println(b);
        String c = b.replace("]", "}");
        System.out.println(c);
        String e = c.replace("\",\"", "\":\"");
        System.out.println(e);
        String f = e.replace("{{", "[{");
        System.out.println(f);
        String g = e.replace("{", "").replace("}", "");
        System.out.println(g);
//        String h = g.replace("[","{").replace("]","}");
//        System.out.println(h);
        String h = "{" + g + "}";
        System.out.printf(h);
        JSONObject jsonObject = JSONObject.parseObject(h);
        System.out.println(jsonObject);
        String d = (String) jsonObject.get("点位");
        System.out.println(d);
    }

    @Test
    public void testt() {
        List<Integer> list = null;
        List<Integer> collect = list.stream().collect(Collectors.toList());

    }
}
